package scheduler

import "spider/concurrent/parser"

type SimpleScheduler struct {
    workerChan chan  parser.Request
}

// 设置调度器分发任务的channel
func (SimpleScheduler *SimpleScheduler) SetMasterWorkerChan(masterWorkerChan chan parser.Request) {
    SimpleScheduler.workerChan = masterWorkerChan
}

// 提交request给调度器
func (SimpleScheduler *SimpleScheduler) Submit(request parser.Request)  {
    // 使用goroutine解决无空闲worker时,
    // 产生循环等待的问题
    go func() {
        // 将request发送到worker channel
        SimpleScheduler.workerChan <- request
    }()
}
